package cn.zucc.edu.handyzucc.service.impl;

import cn.zucc.edu.handyzucc.dao.CommentDao;
import cn.zucc.edu.handyzucc.dao.PostDao;
import cn.zucc.edu.handyzucc.dao.ShopDao;
import cn.zucc.edu.handyzucc.entity.PostCmt;
import cn.zucc.edu.handyzucc.entity.ShopCmt;
import cn.zucc.edu.handyzucc.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentDao commentDao;
    @Autowired
    private PostDao postDao;
    @Autowired
    private ShopDao shopDao;

    @Override
    public List<PostCmt> getPostCommentsByPost(Integer postcmt_post) {
        return commentDao.getPostCommentsByPost(postcmt_post);
    }

    @Override
    public List<PostCmt> getPostCommentsByAuthor(Integer postcmt_author) {
        return commentDao.getPostCommentsByAuthor(postcmt_author);
    }

    @Override
    public boolean addPostComment(PostCmt postCmt) {
        return commentDao.addPostComment(postCmt) == 1;
    }

    @Override
    public boolean deletePostComment(Integer postcmt_id, Integer postcmt_post) {
        return commentDao.deletePostComment(postcmt_id) == 1 && postDao.updatePostComments(postcmt_post, -1) == 1;
    }

    @Override
    public List<ShopCmt> getShopCommentsByShop(Integer shopcmt_shop) {
        return commentDao.getShopCommentsByShop(shopcmt_shop);
    }

    @Override
    public ShopCmt getShopCommentsDetail(Integer shopcmt_id) {
        return commentDao.getShopCommentsDetail(shopcmt_id);
    }

    @Override
    public boolean addShopComment(ShopCmt shopCmt) {
        return commentDao.addShopComment(shopCmt) == 1;
    }

    @Override
    public boolean deleteShopComment(Integer shopcmt_id, Integer shopcmt_shop, Integer shopcmt_rating) {
        return commentDao.deleteShopComment(shopcmt_id) == 1 && shopDao.updateShopRating(shopcmt_shop, -1 * shopcmt_rating, -1) == 1;
    }
}
